package top.datacluster.basic.algorithm.leetcode.queue;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class LeetCode1604 {

    private LinkedList<Integer> max = new LinkedList<>();

    private List<Integer> data = new ArrayList<>();

    public LeetCode1604() {

    }

    public int max_value() {
        if (data.size() == 0){
            return -1;
        }else{
            return max.peekFirst();
        }
    }

    public void push_back(int value) {
        while (!max.isEmpty() && value > max.peekLast()){
            max.removeLast();
        }
        max.offerLast(value);
        data.add(value);
    }

    public int pop_front() {
        if (data.size() == 0){
            return -1;
        }else{
            int result = data.remove(0);
            if (result == max.peekFirst()){
                max.removeFirst();
            }
            return result;
        }
    }
}
